package com.yr.ryjk.listener;

import java.util.Timer;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;

import com.yr.ryjk.common.Constant;
import com.yr.ryjk.consult.autoend.ConsultAutoEndTask;

/**
 * 程序启动时,启动定时任务器
 * @author Rick
 *
 */
public class ContextStartListener implements ServletContextListener{
	private Timer timer=null;
	private Logger logger=Logger.getLogger(this.getClass());
	
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		logger.info("ContextStartListener started...");
		timer=new Timer();
		timer.schedule(new ConsultAutoEndTask(sce.getServletContext()), 
				10000, 
				Constant.consult_scan_interval);         //延迟一分钟，避免获取不到consultService实例;
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		if(timer!=null){
			timer.cancel();
			logger.info("ContextStartListener closed...");
		}
	}
}